package dao;

import entity.User;
import util.JDBCUtils;

import java.sql.Connection;

public class UserDao {
    Connection conn = JDBCUtils.getConnection();

    public User findByName(String userName) {
        String sql = "select id,username,password,name,gender,permission,remark from usertbl where username=?";
        return  JDBCUtils.getObject(sql,User.class,userName);
    }

    public User findById(int id) {
        String sql = "select id,username,password,name,gender,permission,remark from usertbl where id=?";
        return JDBCUtils.getObject(sql, User.class,id);
    }

    public int update(User user) {
        if (user != null){
            String sql = "update usertbl set username=?,name=?,gender=?,permission=?,remark=? where id=?";
            return JDBCUtils.executeUpdate(sql,user.getUsername(),user.getName(),user.getGender(),user.getPermission(),user.getRemark(),user.getId());
        }
        return 0;
    }
}
